// pages/class/class.js
import api from '../../utils/api.js'
Page({
  data: {
    classList: "",
    subCategoryList: "",
    categoryList:"",
    // id: '',
    curIndex: 0
  },
  //事件处理函数  
  switchTab(e) {
    // 获取item项的id，和数组的下标值  
    // let that = this
    console.log(e)
    let index = e.currentTarget.dataset.index;
    // let   id=e.target.dataset.index.id;
    // 把点击到的某一项，设为当前index  
    this.setData({
      // id,
      curIndex: index
    })
  },
  onShow: function() {
    let that = this
    wx.request({
      url: api.classList,
      success: function(res) {
        // console.log(res)
        let classList = res.data.data.categoryList
        // let subCategoryList = res.data.data.categoryList.subCategoryList
        let subCategoryList = res.data.data.currentCategory.subCategoryList
        // console.log(subCategoryList)
        that.setData({
          classList: classList,
          subCategoryList: subCategoryList
        })
      }
    })
    wx.request({
      url: api.indexList,
        success: function(res) {
          let categoryList = res.data.data.categoryList;
          that.setData({
            categoryList
          })
        }
    })
  },
})